package com.ruoyi.dynamic.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dynamic.domain.UserDynamicTime;
import com.ruoyi.dynamic.service.IUserDynamicTimeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 发布活动时间Controller
 * 
 * @author DEREK
 * @date 2023-10-11
 */
@RestController
@RequestMapping("/dynamic/dynamicTime")
public class UserDynamicTimeController extends BaseController
{
    @Autowired
    private IUserDynamicTimeService userDynamicTimeService;

    /**
     * 查询发布活动时间列表
     */
    @PreAuthorize("@ss.hasPermi('dynamic:dynamicTime:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserDynamicTime userDynamicTime)
    {
        startPage();
        List<UserDynamicTime> list = userDynamicTimeService.selectUserDynamicTimeList(userDynamicTime);
        return getDataTable(list);
    }

    /**
     * 导出发布活动时间列表
     */
    @PreAuthorize("@ss.hasPermi('dynamic:dynamicTime:export')")
    @Log(title = "发布活动时间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserDynamicTime userDynamicTime)
    {
        List<UserDynamicTime> list = userDynamicTimeService.selectUserDynamicTimeList(userDynamicTime);
        ExcelUtil<UserDynamicTime> util = new ExcelUtil<UserDynamicTime>(UserDynamicTime.class);
        util.exportExcel(response, list, "发布活动时间数据");
    }

    /**
     * 获取发布活动时间详细信息
     */
    @PreAuthorize("@ss.hasPermi('dynamic:dynamicTime:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(userDynamicTimeService.selectUserDynamicTimeById(id));
    }

    /**
     * 新增发布活动时间
     */
    @PreAuthorize("@ss.hasPermi('dynamic:dynamicTime:add')")
    @Log(title = "发布活动时间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserDynamicTime userDynamicTime)
    {
        return toAjax(userDynamicTimeService.insertUserDynamicTime(userDynamicTime));
    }

    /**
     * 修改发布活动时间
     */
    @PreAuthorize("@ss.hasPermi('dynamic:dynamicTime:edit')")
    @Log(title = "发布活动时间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserDynamicTime userDynamicTime)
    {
        return toAjax(userDynamicTimeService.updateUserDynamicTime(userDynamicTime));
    }

    /**
     * 删除发布活动时间
     */
    @PreAuthorize("@ss.hasPermi('dynamic:dynamicTime:remove')")
    @Log(title = "发布活动时间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userDynamicTimeService.deleteUserDynamicTimeByIds(ids));
    }
}
